package com.zndroid.nfc.core;

import android.content.Intent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zndroid.nfc.NFC;
import com.zndroid.nfc.IAdapter;

/**
 * Created by lzy on 2021/9/9.
 */
public final class Delegate {
    //三种过滤器处理优先级：NDEF > TECH > TAG，由系统接收到NFC信号初步解析后进行分配
    public static final int NDEF = 0;
    public static final int TECH = 1;
    public static final int TAG = 2;

    private IProtocol protocol;

    public Delegate(@NonNull IProtocol protocol) {
        this.protocol = protocol;
    }

    public void consume(int type, @NonNull Intent intent, @Nullable IAdapter adapter) {
        if (null == adapter) {
            NFC.getInstance().logW("'adapter' call back is null", "set 'adapter' call back at first pls.");
            return;
        }

        switch (type) {
            case NDEF:
                protocol.consumeNdef(intent, adapter);
                break;
            case TECH:
                protocol.consumeTech(intent, adapter);
                break;
            case TAG:
                protocol.consumeTag(intent, adapter);
                break;
            default:
                break;
        }
    }
}
